package com.yunlinker.asba.networkcallback;

import com.zhy.http.okhttp.callback.StringCallback;

import org.json.JSONException;
import org.json.JSONObject;

import okhttp3.Call;
import okhttp3.Request;

/**
 * Created by Administrator on 2016/7/14.
 * 公共信息请求,
 */
public abstract class PublicMyStringCallBack extends StringCallback {




    @Override
    public void onError(Call call, Exception e, int id) {//异常处理
//        switch(id){
//            case 0:
////                ToastUtil.show("网络连接失败,请检查网络连接!");
//                break;
//            default:
////                ToastUtil.show("获取信息失败!");
//                break;
//        }
        onError(e.getMessage());

    }

    @Override
    public void onResponse(String response, int id) {//响应结果
        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject(response);
        } catch (JSONException e) {
            e.printStackTrace();
        }
//        String data = jsonObject.optString(UrlApi.DATA, null);
//        int statusCode = jsonObject.optInt(UrlApi.ERROR_CODE,-1);
//        String error = jsonObject.optString(UrlApi.TIP, null);
//        String toastStr = "";
//        switch (statusCode){
//            case 0://成功
//                onResult(data);
//                break;
//            default://默认失败,返回失败信息
                onResult(response);
//                break;
//        }
    }

    @Override
    public void onBefore(Request request, int id) {//记载之前
        super.onBefore(request, id);
    }

    @Override
    public void onAfter(int id) {//加载之后
        super.onAfter(id);
    }

    @Override
    public void inProgress(float progress, long total, int id) {//加载进度
        super.inProgress(progress, total, id);
    }

    public abstract void onResult(String response);

    public abstract void onError(String message);

}
